package com.lyandwc.lw_bbs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lyandwc.lw_bbs.dao.TopicDao;
import com.lyandwc.lw_bbs.entity.Comment;
import com.lyandwc.lw_bbs.entity.Topic;
import com.lyandwc.lw_bbs.entity.TopicTag;
import com.lyandwc.lw_bbs.service.CategoryService;
import com.lyandwc.lw_bbs.service.CommentService;
import com.lyandwc.lw_bbs.service.TopicService;
import com.lyandwc.lw_bbs.service.TopicTagService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TopicServiceImpl extends ServiceImpl<TopicDao, Topic> implements TopicService {
    @Override
    public Topic findTopic(int id) {
        return this.baseMapper.findTopicById(id);
    }

    @Override
    public List<Topic> listTopicsByCategory(int categoryId, int page, int limit) {
        return this.baseMapper.listTopicsByCategoryId(categoryId, (page - 1) * limit, limit);
    }

    @Override
    public List<Topic> listTopicsByUser(int userId, int page, int limit) {
        return this.baseMapper.listTopicsByUserId(userId, (page - 1) * limit, limit);
    }

    @Override
    public List<Topic> listTopicsByTag(int tagId, int page, int limit) {
        return this.baseMapper.listTopicsByTagId(tagId, (page - 1) * limit, limit);
    }

    @Override
    public Topic updateCount(int topicId) {
        this.baseMapper.updateTopicCountById(topicId);
        return this.baseMapper.selectById(topicId);
    }
}
